#!/usr/bin/env python
# -*- coding:utf-8 -*-
import MySQLdb

conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='123',db='mydb')
cur = conn.cursor()    #打开游标

reCount = cur.execute(
    'insert into UserInfo(Name,Address) values(%s,%s)',
    ('test','beijing')
)   #与字符串格式化不一样，mysql只有%s，没有别的，数字什么的也都用%s
# reCount = cur.execute('insert into UserInfo(id,Name) values(%(id)s, %(name)s)',{'id':12345,'name':'test1'})

cur.lastrowid()     #获取新插入的数据的自增ID
conn.commit()
cur.close()
conn.close()
print reCount